# 用 python 打开 simple.txt 并读入其内容
file_path = "simple.txt"
print(f"尝试访问文件: {file_path}")

with open(file_path, 'r') as file:
    content = file.read()
    print("文件内容:", content)
# Output: 尝试访问文件: simple.txt
# Output:文件内容: tobrvtBCWR9vdx8rE9UpoYCk


# 再次读取
# file_path = "C:\new_folder\test.txt"
# print(f"尝试访问文件: {file_path}")

# # 这会报错！
# with open(file_path, 'r') as file:
#     content = file.read()
#     print("文件内容:", content)
    
    
# 方法1：使用原始字符串（推荐）
file_path = r"C:\new_folder\test.txt"
print(f"方法1 - 原始字符串: {file_path}")

# 方法2：使用正斜杠（跨平台兼容）
file_path = "C:/new_folder/test.txt"
print(f"方法2 - 正斜杠路径: {file_path}")

# 方法3：双重转义
file_path = "C:\\new_folder\\test.txt"
print(f"方法3 - 双重转义: {file_path}")

# 现在可以安全使用了
with open(file_path, 'r') as file:
    content = file.read()
    print("文件内容:", content)
    print("文件读取成功！")
    
 #Output:方法1 - 原始字符串: C:\new_folder\test.txt
 #       方法2 - 正斜杠路径: C:/new_folder/test.txt
 #       方法3 - 双重转义: C:\new_folder\test.txt
 #       文件内容: tobrvtBCWR9vdx8rE9UpoYCk
 #       文件读取成功！